package com.htj.admin.controller;

import com.htj.admin.domain.Food;
import com.htj.admin.domain.FoodType;
import com.htj.admin.service.FoodTypeServiceInf;
import com.htj.common.Result;
import com.htj.vo.PageListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping(value = "type")
@CrossOrigin
public class FoodTypeController {
    @Autowired
    FoodTypeServiceInf orderTypeServiceInf;
    /**
     * 新增菜品
     * @param orderType
     * @return
     */
    @PostMapping("/save")
    public Result<String> add(@RequestBody FoodType orderType){
        boolean bool = orderTypeServiceInf.add(orderType);
        return bool?Result.succ():Result.fail();
    }

    /**
     * 修改菜品类型
     * @param  orderType
     * @return
     */
    @PutMapping("/save")
    public Result<String> update(@RequestBody FoodType orderType){
        boolean bool = orderTypeServiceInf.update(orderType);
        return bool?Result.succ():Result.fail();
    }
    /**
     * 分页数据
     * @param currentPage
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/pageList")
    public Result<PageListVo> pageList(@RequestParam String currentPage,
                                       @RequestParam String pageSize,
                                       @RequestParam String name){
        HashMap<String, String> map = new HashMap<>();
        map.put("currentPage",currentPage);
        map.put("pageSize",pageSize);
        map.put("name",name);
        PageListVo<Food> pageList = orderTypeServiceInf.pageList(map);
        return Result.succ(pageList);
    }

    /**
     * 删除菜品
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public Result<String> delete(@PathVariable Integer id){
        boolean bool = orderTypeServiceInf.delete(id);
        return bool?Result.succ():Result.fail();
    }
    /**
     * 批量删除
     * @param list
     * @return
     */
    @PostMapping("/deleteByIds")
    public Result<String> deleteByIds(@RequestBody List<Integer> list){
        boolean bool = true;
        for(Integer id : list){
            bool = orderTypeServiceInf.delete(id);
        }
        return bool?Result.succ():Result.fail();
    }
    @GetMapping("/getOrderType")
    public Result<List<FoodType>> getOrderType(){
        List<FoodType> list = orderTypeServiceInf.getOrderType();
        return Result.succ(list);
    }
}
